<template>
	<view>

		<!-- 404页面 -->
		<!-- <view class="noData" v-if="netWorkType == 'none'">
			<noData @handle="refresh"></noData>
		</view> -->
		<view>
		
			<view class="content-wrap">
				<view >
					<!-- 地址 -->
					<view class="address-box"  v-if="data.list.deliver_type==0" >
						<view class="iconfont location">&#xe628;</view>
						<view class="name-phone-address">
							<view class="item">{{data.list.deliver_name||''}} {{data.list.deliver_tel||''}} </view>
							<view class="item">{{data.list.deliver_address||''}} </view>
						</view>
						<!-- <view class="right-icon iconfont">&#xe62b;</view> -->
					</view>
					<view class="address-box"   v-if="data.list.deliver_type==1">
						<view class="iconfont location">&#xe628;</view>
						<view class="name-phone-address">
							<view class="item">{{data.list.deliver_store_name||''}} {{data.list.store_tel||''}} </view>
							<view class="item">{{data.list.store_province_name||''}} {{data.list.store_city_name||''}}{{data.list.store_area_name||''}}{{data.list.store_address||''}}</view>
						</view>
						<!-- <view class="right-icon iconfont">&#xe62b;</view> -->
					</view>
					<view class="store-box">
						<view class="left-text" style="display: flex;" v-if="data.list.related_type !=6">
							<!-- <text style="color:#fed369;" class="iconfont">&#xe676;</text> -->
							<view><img src="http://img.aiouning.com/uploader/upload/202202/11/202202110918506205b97a9deab.png" alt="" style="width: 40rpx;height: 40rpx;"></view>
							
							<text style="margin-left: 14rpx;">配送上门</text>
						</view>
						<view class="right-text">
							<!-- 租赁中 -->
							<!-- <text v-if="data.list.order_estate=='used_pending_payment'">租赁中</text> -->
							<!-- <text v-if="item.order_estate==''">运输中</text> -->
							<text v-if="data.list.order_estate=='completed'">已完成</text>
							<text v-if="data.list.order_estate=='pending_payment'">未付款</text>
							<text v-if="data.list.order_estate=='sign_for'">已签收</text>
						</view>
						
						
					</view>
					<!-- 商品  多个-->
					<view class="goods-box" v-for="item in data.list.sub">
						<view class="goods-img">
							<!-- 6 会员卡 -->
							<image :src="item.related_type!=6?item.cover_image:''" ></image>
						</view>
						<view class="goods-describe">
							<view class="small-text" style="display: flex; justify-content: flex-end;">{{item.order_estate_name||''}} </view>
							<view class="main-title">{{item.related_name!='null'?item.related_name:''}}  </view>
							<view class="small-text">{{item.norms_value_name!='null'?item.norms_value_name:''}}</view>
							<view class="small-text">订单号：{{item.order_no}}</view>
							<view class="small-text">价格：￥{{item.related_price}}</view>
							<view class="small-text">数量：x{{item.related_num}}</view>
							<view class="small-text">金额：{{item.amount}}</view>
							<view  class="small-text">
								<view>物流单号：</view>
								<view style="display: flex;    flex-wrap: wrap;">
									<view class="" v-for="v in item.deliveryids" @tap = "toLogistics(v)" style="padding: 20rpx ;">
										{{v}}
									</view>
								</view>
								
								<view class="small-text">点击物流号可查看物流信息</view>
							</view>
							<view class="rent-pay blue" v-if="item.order_estate!='1' && item.order_estate!='4'  && item.order_estate!='8'" @tap.stop="applyRefund(item.id)">申请退款</view>
						</view>
						<view class="line"></view>
					</view>
					
					<view style="background-color: #fff;">
						<view class="row-cell-box" style="    margin-top: 30rpx;">
							<view>付款号</view>
							<view class="righr-part">{{data.list.trade_no}}</view>
						</view>
						<view class="row-cell-box">
							<view>下单时间</view>
							<view class="righr-part">{{data.list.createTime}}</view>
						</view>
						<view class="row-cell-box" v-if='data.list.order_estate ==1'>
							<view>订单15分钟内有效，超出自动取消</view>
							<!-- <view class="righr-part">{{data.list.create_time}}</view> -->
						</view>
						<view class="row-cell-box">
							<view>对公凭证：</view>
							<view class="righr-part">
								<image class="i-img" :src="v.src" mode="" v-for="v in data.list.pubpay_img"></image>
							</view>
						</view>
						<view class="row-cell-box">
							<view>对公流水号：</view>
							<view class="righr-part">
								{{data.list.callback_trade_no}}
							</view>
						</view>
						<view class="row-cell-box"  v-if="data.list.related_type !=6">
							<view>配送方式</view>
							<view class="righr-part" v-if="data.list.deliver_type==1">门店自提</view>
							<view class="righr-part" v-else>配送上门</view>
						</view>
						
						<!-- <view class="row-cell-box">
							<view>押金（￥{{data.list.cash}}）</view>
							<view class="righr-part">{{data.list.cash_type == 1?'在线支付':'微信免押'}}</view>
						</view>
						<view class="row-cell-box">
							<view>套餐金额</view>
							<view class="righr-part">￥{{data.list.package_price}}</view>
						</view> -->
						<view class="row-cell-box" v-if="data.list.coupon_id" >
							<view>优惠券</view>
							<view class="righr-part">-￥{{data.list.coupon_fee}}</view>
						</view> 
						<view class="row-cell-box" >
							<view>合计金额</view>
							<view class="righr-part">￥{{data.list.amount}}</view>
						</view>
						<!-- <view class="row-cell-box">
							<view>优惠</view>
							<view class="righr-part" @tap="useCoupon()">
								<view class="i-item manjian-bg">满减券</view>
								<view class="i-item" v-if="couponMoney>0">-￥{{couponMoney}}</view>
								<view class="iconfont">
									&#xe62b;
								</view>
							</view>
						
						</view> -->
						<!-- <view class="row-cell-box">
							<view>租赁门店</view>
							<view class="gray">{{data.list.store_name}}</view>
						</view>
						<view class="row-cell-box">
							<view>押金（￥{{data.list.cash}}）</view>
							<view class="gray">{{data.list.cash_type == 1?'在线押金':'微信免押'}}</view>
						</view>-->
						<view class="footer-box row-cell-box1" style="border-top: 2rpx solid #e6e6e6; margin-top: 20rpx; padding: 20rpx 30rpx;">
							<view class="rent-fee"></view>
							<!-- <view class="rent-pay" v-if="data.list.order_estate=='shipping' & data.list.deliver_type==1" style="background-color: #888;" >扫码提货</view> -->
							<!-- <view class="rent-pay" v-if="data.list.order_estate=='shipping' &data.list.deliver_type==0" style="background-color: #888;" >配送中</view> -->
							<!-- <view class="rent-pay"   @click="toLogistics()" v-if="data.list.deliver_type!=1 && data.list.order_estate!=1 && data.list.related_type !=6" >物流查询</view> -->
							<!-- <view class="rent-pay"   @click="closeOrder()" v-if="data.list.order_estate==1"  >取消订单</view> -->
							<view class="rent-pay blue" v-if="data.list.order_estate!='1' && data.list.order_estate!='4'  && data.list.order_estate!='8' && data.list.order_estate!='16' &&data.list.order_estate!='17' " @tap.stop="applyRefund()">申请退款</view>
							<view class="rent-pay blue" v-if="data.list.order_estate=='4'  || data.list.order_estate =='8'" @tap.stop="toRefundFlow(1)">查看进度</view>
							<view class="rent-pay"   @click="pay()" v-if="data.list.order_estate==1"  >支付</view>
							<view class="rent-pay"   @click="qrCode()" v-if=" data.list.deliver_type == 1 && data.list.order_estate >1"  >自提码</view>
							<view class="rent-pay"   @click="upPubpay()" v-if=" data.list.order_estate == 16 || data.list.order_estate !=17"  >上传凭证</view>
						</view> 
					</view>
					<view style="height: 100rpx;"></view>     
					
					
					
				</view>
				
			</view>
			<!-- 底部固定栏 -->
			
			<!-- 优惠卷弹窗 -->
			<coupon-popup ref="couponPopup" :couponList='data.couponList' :show='showCouponPopup' :couponId='couponId'
			 @getOverAndSale='getOverAndSale' @maskClose='maskClose'>

				<view slot='close-coupon-popup' @click="closeCouponPopup">x</view>

			</coupon-popup>
			<!-- 优惠卷弹窗end -->
			<!-- 日历时间弹窗 -->
			<uni-popup ref="datePopup" type="bottom" :custom="true">
				<view style="height:450upx;" class="carts-date-list">
					<view class="action-box">
						<view class="cancel-btn">取消</view>
						<view class="confirm-btn" @click="backDateFun">确定</view>
					</view>
					<picker-view class="picker-view" :indicator-style="indicatorStyle" :value="value" @change="bindChange">
						<picker-view-column>
							<view class="item" v-for="(item,index) in years" :key="index">{{item}}</view>
						</picker-view-column>
						<picker-view-column>
							<view class="item" v-for="(item,index) in months" :key="index">{{item}}</view>
						</picker-view-column>
						<picker-view-column>
							<view class="item" v-for="(item,index) in days" :key="index">{{item}}</view>
						</picker-view-column>
						<picker-view-column style="flex: 2;">
							<view class="item" v-for="(item,index) in timeRangs" :key="index">{{item}}</view>
						</picker-view-column>
					</picker-view>
				</view>
			</uni-popup>
			
			<!-- 核销二维码 -->
			<uni-popup ref="qrImg" type="center" :custom="true" >
				<view class="qrImg-box">
					<view class="title">
						提取码
					</view>	
					<view class="text">
						店员扫码确认自提取货
					</view>
					<view class="closs" @tap.stop="$refs.qrImg.close()">
						x
					</view>
					<view class="qr-img-big" >
						<img :src="qrcode_img" alt="" mode="">
						<!-- <img  src="http://api.xingdongty.com/uploader/upload/202207/16/2022071610093962d21de3cab4d.png" alt=""> -->
					</view>	
				</view>
				
			</uni-popup>
			<!-- 申请退款 -->
			<uni-popup ref="refunds" type="bottom" :custom="true" >
				<view class="refund-box">
					<view class="title">
						请选择类型
					</view>	
					<!-- <view class="text">
						确认退款
					</view> -->
					<view class="closs" @tap.stop="$refs.refunds.close()">
						x
					</view>
					<view class="content" >
						<view class = 'refundProduct border-bottom' @tap.stop="toRefundFlow(1)">
							<view class="tit"><text class="iconfont"></text>退货退款</view>
							<view > <text class="iconfont">&#xe626;</text></view>
							<!-- <view class="tip">已收到货，需要退还已收到的货</view> -->
						</view>
						<view class = 'refundProduct border-bottom' @tap.stop="toRefundFlow(2)">
							<view class="tit">仅退款</view>
							<view > <text class="iconfont">&#xe626;</text></view>
							<!-- <view class="tip">未收到货，或与商家协商之后申请</view> -->
						</view>
						<view class = 'refundProduct' @tap.stop="toRefundFlow(3)">
							<view class="tit"><text class="iconfont"></text>换货</view>
							<view > <text class="iconfont">&#xe626;</text></view>
							<!-- <view class="tip">对已收到货不满意，与商家协商换货</view> -->
						</view>
						
					</view>	
				</view>
				
			</uni-popup>		
			<!-- 上传凭证 -->
			<uni-popup ref="upPubpayModal" type="bottom" :custom="true" >
				<view class="upPubpay-box">
					<view class="title">
						上传对公转账凭证
					</view>	
					<!-- <view class="text">
						确认退款
					</view> -->
					<view class="closs" @tap.stop="$refs.upPubpayModal.close()">
						x
					</view>
					<view class="content " >
						<view class="tip">
							温馨提示：上传转账凭证图和凭证上的流水号或凭证号等，<span style="color: red;">如果无法上传图片，联系客服帮您处理图片上传，</span>3天内未上传转账凭证和流水号将自动取消该订单.
						</view>
						<view class="tip-box">
							<view class="">
								<view class="txt">上传对公凭证(限制2M以内)：</view>
								<view class="input-box"><tui-upload :limit="2" :dirType="0" :userType="2" :serverUrl="serverUrl" @complete="result($event,'pubpay_img')" @remove="remove($event,'pubpay_img')"></tui-upload></view>
							</view>
							<view class="tip-txt">
								<view class="txt">流水号：</view>
								<view class="input-box"><input type="text" name="" v-model="callback_trade_no" placeholder="请输入凭证上的流水号或凭证号" ></view>
							</view>
							
							<view class="tip-txt">
								<view class="txt">公司名称：</view>
								<view class="input-box">广西瓯宁医疗科技有限公司</view>
							</view>
							<view class="tip-txt">
								<view class="txt">开户行：</view>
								<view class="input-box">兴业银行南宁分行</view>
							</view>
							<view class="tip-txt">
								<view class="txt">税号：</view>
								<view class="input-box">9145010006174381XR</view>
							</view>
							<view class="tip-txt">
								<view class="txt">账号：</view>
								<view class="input-box">552010100100607698</view>
							</view>
							<view class=" tip-btn" @tap.stop='copyText'>
								<view class="iconfont">
									&#xe661;
								</view>
								<view class="txt">
									复制
								</view>
							</view>
							<view class="" style="height: 100rpx;">
								
							</view>
						</view>
						
						
					</view>	
					<view class="footer">
						<!-- <view class="btn-close btn">
							取消
						</view> -->
						<view class="btn-comfir btn" @tap.stop = "upPubpayImg()">
							确认提交
						</view>
					</view>
				</view>
				
			</uni-popup>
			<!-- 日历时间弹窗end -->
			<!-- 提示弹框 -->
			<tui-tips ref="toast"></tui-tips>
			<!-- 登录弹框 -->
			<uni-popup-vlogin id="popupvLogin" ref="popupvLogin" type="bottom" />

		</view>
	</view>
</template>

<script>
	// cj引入优惠卷弹窗
	// import couponPopup from "@/components/coupon-popup/coupon-popup"
	
	// import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
	const QR = require('@/utils/wxqrcode.js');
	// import QRCode from 'qrcodejs2';
	import tuiUpload from '@/components/tui-upload/tui-upload'
	import Vue from 'vue' 
	import store from '@/store/index.js';

	//获取网络状态
	import {
		mapGetters
	} from 'vuex';
	export default {
		components: {
			// QRCode
			// tuiButton,
			// tuiListCell,
			// tuiBottomPopup,
			// mpvuePicker,
			// tuiSkeleton,
			// couponPopup
			tuiUpload
		},

		computed: {
			//注册网络状态
			...mapGetters(['netWorkType','loginStatus']),
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		data() {
			// const currentDate = this.getDate({
			// 	format: true
			// })
			const date = new Date()
			const years = []
			const year = date.getFullYear()
			const months = []
			const month = date.getMonth() + 1
			const days = []
			const day = date.getDate()
			for (let i = 1990; i <= date.getFullYear(); i++) {
				years.push(i)
			}
			for (let i = 1; i <= 12; i++) {
				months.push(i)
			}
			for (let i = 1; i <= 31; i++) {
				days.push(i)
			}
			return {
				backDate:'',
				title: 'picker-view',
				years,
				year,
				months,
				month,
				days,
				timeRangs:["08:00-10:00","10:00-12:00","12:00-14:00","14:00-16:00","16:00-18:00","18:00-20:00","20:00-22:00"],
				day,
				time:'08:00-10:00',
				value: [9999, month - 1, day - 1],
				visible: true,
				indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth/(750/100))}px;`,

				//date: currentDate,
				couponId: '',
				couponName: '',
				showCouponPopup: false,
				couponMoney: 0,
				skeletonShow: true,
				id: 53,
				token: '', //normsValue id
				skuL: '', // sku
				//配送方式
				deliver_type: 0,
				month_card_id: 8,
				hasCoupon: true,
				insufficient: false,
				
				refund_trade_no:'',// 申请退款
				refund_order_id:'',
				data: {
					list: {
						amount: [0, 0]
					},
					address: {},
					monthcard: {},
					//自提列表
					deliver_store: [],
					//配送设置
					deliver_option: {},
					couponList: [], //优惠券数据
				},
				cartList:[],
				qrcode_img:'',
				//下拉数据
				deliverStoreArray: [],
				deliverStoreObj: {
					text: '选择自提地址',
					key: '',
					val: ''
				},
				pageStyle: 1,
				//备注
				remark: '',
				
				// 留言
				leavingAMessage: '',
				//使用的优惠券
				selectCoupon: {
					name: '可使用',
					coupon_money: 0,
					coupon_id: 0
				},
				serverUrl:'',//上传图片链接
				pubpay_img:[],
				callback_trade_no:'',
				up_trade_no:'',

			}
		},
		onLoad: function(e) {
			console.log(e)
			console.log('1212')
			this.data.list = JSON.parse(e.list)
			this.serverUrl = this.$service.getImgHost()
			console.log(this.data.list)
			this.cartList = uni.getStorageSync('cartList')==''?{}:JSON.parse(uni.getStorageSync('cartList'))
			
			// this.orderId = e.order_id;
			// this.data.list.sumVal = parseFloat(this.data.list.delivers.split(',')[0]) + parseFloat(this.data.list.rent_fee)


		},
		onShow() {
			const _this = this

			//设置默认地址
			// uni.getStorage({
			// 	key: 'selectAddress',
			// 	success: (e) => {
			// 		this.data.address = e.data;
			// 		console.log(e)

			// 	},
			// 	fail: () => {
			// 		//初始默认地址

			// 		var opt = {
			// 			url: '/address/defaultAddress',
			// 			success: function(res) {
			// 				//console.log(res)
			// 				if (res.status == 1) {
			// 					_this.data.address = res.data.address

			// 				} else {

			// 				}

			// 			}
			// 		};
			// 		_this.$service.GetApi(opt)
			// 	}
			// })
		},
		methods: {
			bindChange: function(e) {
				const val = e.detail.value
				this.year = this.years[val[0]]
				this.month = this.months[val[1]]
				this.day = this.days[val[2]]
				this.time= this.timeRangs[val[3]];
				
				
				console.log(this.time)
			},
			// 用户上传对公凭证
			upPubpay(item){
				let _this = this
				_this.trade_no = item.trade_no
				_this.$refs.upPubpayModal.open()
			},
			// 用户上传对公凭证
			upPubpayImg(){
				
				let _this = this
				// console.log('payment_id轮询---', uni.getStorageSync('payment_id'))
				var opt = {
					url: '/order/pubpayImgUp',
					data: {
						trade_no: _this.trade_no,
						callback_trade_no:_this.callback_trade_no,
						pubpay_img:_this.pubpay_img||['1.png']
					},
					success: function(res) {
						if (res.status == 1) {
							// 取消成功
							// console.log(res)
							_this.$refs.upPubpayModal.close()
							_this.curr_page = 0
							_this.getList()
							
						} else {
							console.log(res.message)
						}
							
					}
				};
							
				uni.showModal({
					title: '温馨提示',
					content: '再次确认提交',
					success: function (res) {
						_this.$service.GetApi(opt) //网络
					}
				})
			},
			applyRefund(orderId){
				let _this = this
				// _this.refund_trade_no = tradeNo
				_this.refund_order_id = orderId
				_this.$refs.refunds.open()
			},
			// 时分秒 倒计时  结束时间  that ->this
			time1(timeStamp,that) {
			  var interval = null,totalSecond = timeStamp - Date.parse(new Date()) / 1000;
			  interval = setInterval(function () {
			    // 秒数  
			    var second = totalSecond;
			
			    // 小时位  
			    var hr = Math.floor(second / 3600);
			    var hrStr = hr.toString();
			    if (hrStr.length == 1) hrStr = '0' + hrStr;
			
			    // 分钟位  
			    var min = Math.floor((second - hr * 3600) / 60);
			    var minStr = min.toString();
			    if (minStr.length == 1) minStr = '0' + minStr;
			
			    // 秒位  
			    var sec = second - hr * 3600 - min * 60;
			    var secStr = sec.toString();
			    if (secStr.length == 1) secStr = '0' + secStr;
			   
			      this.countDownHour= hrStr,
			      this.countDownMinute= minStr,
			      this.countDownSecond= secStr,
			    
			    totalSecond--;
			    if (totalSecond <= 0) {
			      clearInterval(interval);
			      uni.showToast({
			        title: '活动已结束',
			        icon: 'none',
			        duration: 1000,
			        mask: true,
			      })
			     
					this.countDownHour= '00'
			      this.countDownMinute= '00'
			      this.countDownSecond= '00'
			      
			    }
			  }.bind(this), 1000);
			  this.interval=interval;
			},
			// 进入退款流程  1退货退款  2.退款  3.换货
			toRefundFlow(type){				
				let _this= this
				
				_this.$refer.setVilit('/pages/OrderRefund/index')
				let callback = function(url) {
					_this.$refs.popupvLogin.open()
				}
				let data = {
					trade_no:_this.data.list.trade_no,
					order_no:'',//预留 单退
					type:type,
					list:JSON.stringify(_this.data.list)
					
				}
				_this.$refer.toUrl(callback, data)
			},
			nowPay(id) {
			
				const _this = this
			
				let data = {
					id:id
				}
			
				
				// #ifdef  MP-WEIXIN || APP-PLUS
				//获取服务商
				var opt = {
					url: '/order/payOutOrder',
					data: data,
					success: function(res) {
						//console.log(res)
						if (res.status == 1) {
							
							
							// #ifdef  MP-WEIXIN
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: res.data.list.timeStamp,
								nonceStr: res.data.list.nonce_str,
								package: 'prepay_id=' + res.data.list.prepay_id,
								signType: 'MD5',
								paySign: res.data.list.paySign,
								success: function(res) {
			
									if (res.errMsg == 'requestPayment:ok') {
										let options = {
											msg: '支付成功',
											type: 'green'
										};
										_this.$refs.toast.showTips(options);
										_this.topTabActive=3;
										_this.curr_page=0;
										// _this.getOutProcessList()
			
										_this.$refer.setVilit('/packageUser/pages/user/pay/pay-success');
			
										let callback = function(url) {
											_this.$refs.popupvLogin.open()
										}
										var data = {
											amount:res.data.list.payment,
											product_name:_this.data.list.remark
										}
										_this.$refer.toUrl(callback, data, 'reLaunch')
			
									}
								},
								fail: function(err) {
									//console.log(err.errMsg)
									//console.log('fail:' + JSON.stringify(err));
									if (err.errMsg == 'requestPayment:fail cancel') {
			
										var opt = {
											url: '/coupon/clearCoupon',
											data: {
												order_no: store.getters.orderNo
												// order_no:"202010171849465f8acc4a24cca"
											},
											success: function(res) {
			
											},
										}
			
										_this.$service.GetApi(opt);
										let options = {
											msg: '取消支付',
											type: 'danger'
										};
										_this.$refs.toast.showTips(options);
										return
									} else {
										let options = {
											msg: JSON.stringify(err),
											type: 'danger'
										};
										_this.$refs.toast.showTips(options);
									}
								}
							});
							// #endif 	
			
						} else if (res.status == 0 && res.code == 1000) {
							//未付押金
							//些处pid为product表的id   
							// uni.navigateTo({
							// 	url:"../cash/cash?pid="+_this.productId
							// })
						} else {
			
							let options = {
								msg: res.message,
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);
			
						}
			
					}
				};
			
				_this.$service.GetApi(opt)
				// #endif 
			
			},
			
			// 核销
			//适配不同屏幕大小的canvas
			getQRCodeSize: function() {
				var size = 0;
				try {
					var res = wx.getSystemInfoSync();
					var scale = res.windowWidth / 750; //不同屏幕下QRcode的适配比例；设计稿是750宽
					var width = 300 * scale;
					size = width;
				} catch (e) {
					// Do something when catch error
					console.log("获取设备信息失败" + e);
					size = 150;
				}
				return size;
			},
			createQRCode: function(text, size) {
				// https://blog.csdn.net/qdm13209211861/article/details/107962001
				//调用插件中的draw方法，绘制二维码图片
				// text ='111'
				let that = this
				try {
					console.log('QRcode: ', text, size)
					let _img = QR.createQrCodeImg(text, {
						size: parseInt(size)
					})
					that.qrcode_img = _img;
					console.log(that.qrcode_img,'**********')
					// that.setData({
					//   'qrcode': _img
					// })
				} catch (e) {
					console.warn(e)
				}
			
			},
			qrCode(row) {
				// this.currentQrCodeProduct = row;
				this.$refs.qrImg.open()
				let qrcodeSize = this.getQRCodeSize()
				
				let  cancel_code ='param/?trade_no=' +this.data.list.trade_no
				// console.log(row.code)
				this.createQRCode(cancel_code, qrcodeSize)
			},
			
			backDateFun(){
				this.$refs['datePopup'].close();
				let yearMonthDay=this.year+'-'+this.month.toString().padStart(2,0)+'-'+this.day.toString().padStart(2,0);
				let week=new Date(yearMonthDay).getDay();
				let weekText='';
				switch(week){
					case 0:
					weekText='(星期日)'
					break;
					
					case 1:
					weekText='(星期一)'
					break;
					
					case 2:
					weekText='(星期二)'
					break;
					
					case 3:
					weekText='(星期三)'
					break;
					
					case 4:
					weekText='(星期四)'
					break;
					
					case 5:
					weekText='(星期五)'
					break;
					
					case 6:
					weekText='(星期六)'
					break;
					
					
				}
				console.log(week)
				this.backDate=this.year+'-'+this.month.toString().padStart(2,0)+'-'+this.day.toString().padStart(2,0)+' '+weekText+'  '+this.time;
			},
			// 物流查询
			toLogistics(deliveryid =''){
				let _this=this
				// uni.showToast({
				// 	icon: 'none',
				// 	title: '开发中'
				// })
				// return 
				
				var data = {
					orderNo:_this.data.list.trade_no,
					deliveryid:deliveryid!=''?deliveryid: _this.data.list.deliveryid, //物流运单号
					to:_this.data.list.deliver_address,
					from:'广西南宁市' //暂时固定
				}
				
				//公共物流查询页面
				// console.log(1111)
				_this.$refer.setVilit('/pages/Order/logistics/logistics')
				let callback = function(url) {
					_this.$refs.popupvLogin.open()
				}
				
				
				_this.$refer.toUrl(callback, data)
			},
			
			selectDate() {
				this.$refs['datePopup'].open()

			},
			pendingRefund(desStr){
				//申请退押金
				const _this = this
				desStr = _this.$service.decryptDes(desStr)
				let orderNo = _this.$service.decryptDes(desStr)
				orderNo = _this.$service.encryptDes(orderNo)
				// console.log(orderNo)
				uni.showModal({
				    title: '提示',
				    content: '是否确定提现?',
				    success: function (res) {
				        if (res.confirm) {
				            var opt={
				            	url:'/cash/pendingRefund',
				            	data:{
				            		order_no:orderNo				
				            	},
				            	success:function(res){
				            		//console.log(res)
				            		if(res.status==1){
				            			let options = {
											msg: '提交申请成功',
											type:'green'
				            			};						
										_this.$refs.toast.showTips(options);
										_this.curr_page = 0
										_this.getList()
				            		}else{
				            			 let options = {
											msg: res.message,
											type:'danger'
										  };								
										_this.$refs.toast.showTips(options);
				            		
				            		}
				            									
				            	}
				            };
				            						
				            _this.$service.GetApi(opt)	
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				
				
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			bindDateChange() {

			},
			
			backFun() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 刷新的方法
			refresh() {
				window.addEventListener('pageshow', this.onShow);
			},
			getPayStore(item,type) {
				this.couponObj = item;
				const _this = this
				// 清缓存
				_this.data.storeaddress = []
				if(type=='store'){
					console.log('123456',item)
					 //后台手动创建门店租赁订单 未付款
					 if(item.channel==5 && item.order_estate=='pending_payment'){
						  _this.$refer.setVilit('/packageOrder/pages/store/storeRentPay')
					 }else{
						 _this.$refer.setVilit('/packageOrder/pages/store/returnProduct')
					 }
					 
				}else if(type == 'monthcard'){
					_this.$refer.setVilit('/packageStore/pages/month_card/buy_month_card/buy')
				}
				else{
					_this.$refer.setVilit('/packageOrder/pages/online/returnProduct')
				}
			
				
				let callback = function(url) {
					_this.$refs.popupvLogin.open()
				}
			
				var data = item;
				if(type == 'monthcard'){
					 data = {
						 class_id:item.class_id,
						 is_renew:1,
						 month_order_id:item.month_card_order_id,
						 
					 }
						 
					 
				}
				if(item.channel==5){
					 
					data = item;
					data.bid = item.business_id;
					data.cid = item.class_id;
					data.storeaddressId = item.store_id;
					data.storeName = item.store_name; 
					data.selectMonthCard=JSON.stringify([]);
					data.usableCash = '' 
					data.user_month_card=JSON.stringify(item.userMonthCard);
					data.monthcard_pay=item.userMonthCard.status;
					data.isMonthCardPay = !item.userMonthCard.status ? 'noPay' : 'pay';
					// console.log('-*-*-*',data)
					// return ;
				}
			 
				// return false;
				_this.$refer.toUrl(callback, data)
			
			},
			//再次支付提交
			pay() { 
				
				const _this =this				
				var opt = {
					url: '/product/rewxPay',
					data:{
						trade_no:_this.data.list.trade_no,
						related_type:_this.data.list.related_type,
						deliver_type:_this.data.list.deliver_type,
					},
					success: function(res) {
						if (res.status == 1) {
							console.log('****',res.data.list.time_stamp)
							// _this.showMaskloading = false;
							uni.setStorage({
								key: "payment_id",
								data: res.data.list.order_payment_id //需要存储的数据
							})
							
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: res.data.list.time_stamp.toString(),
								nonceStr: res.data.list.nonce_str,
								package: 'prepay_id=' + res.data.list.prepay_id,
								signType: 'MD5',
								paySign: res.data.list.pay_sign,
								success: function(res) {
									
									
			
									if (res.errMsg == 'requestPayment:ok') {
									
										_this.showMaskloading = true;
										//支付成功清除购物车
										let payCartList = JSON.parse(_this.product)
										// console.log('***',payCartList)
										// if(_this.type == 'cart' ){
										// 	payCartList.forEach(function(v){
										// 		// console.log('*****v',v)
										// 		//删除购物车商品
										// 		let goods = {norms_value_id:v.norms_value_id,store_id:v.store_id}  
												
										// 		cart.delProd(goods,_this.cartList,function(res){
										// 			uni.setStorageSync('cartList',JSON.stringify(res.data.cartList))
										// 			_this.cartList = res.data.cartList
										// 		});
										// 	})
										// 	uni.setStorageSync('payCartList',JSON.stringify({}))
											
										// }
										_this.successTime = setInterval(() => {
											console.log('successTime轮询---')
											_this.checkShopOrderEstate();
										}, 2000) 
										
									}
			
								},
								fail: function(err) {
									console.log(err)
									
									if(	_this.successTime != ''){
										clearInterval(_this.successTime);
										_this.successTime = '';
									}
								 
								}
							});
			
			
			
						} else {
							let options = {
								msg: res.message,
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);
							return
						}
			
					}
				};
			
				if (this.loginStatus) {
					this.$service.GetApi(opt) //网络
				}
			
			},
			pay1() {
				//扫码归还
				let _this = this;
				let options = {
					msg:'请选择归还时间',
					type: 'danger'
				};
				if(!this.backDate){
					_this.$refs.toast.showTips(options);
					return;
				}
				
				let data = {
					deliver_type: _this.deliver_type,
					id: _this.data.list.id
				}
				data.address = _this.data.address.province_name + _this.data.address.city_name + _this.data.address.area_name +
					_this.data.address.detail
				data.name = _this.data.address.name
				data.tel = _this.data.address.tel
				data.deliver_store_id = 0
				data.coupon_id = _this.couponId;
				data.send_star_time=this.backDate.substring(0,10)+' '+this.time.substring(0,5)+':00';
				data.send_end_time=this.backDate.substring(0,10)+' '+this.time.substring(6,11)+':00';
				//name,address,coupon_id,tel,deliver_store_id=0,id

				var opt = {
					url: '/order/shopRurnPay',
					data: data,
					success: function(res) {
						//console.log(res)
						if (res.status == 1 && res.code == 0) {
							store.dispatch('setOrderNo', res.data.list.order_no)
							// #ifdef  H5
							jweixin.chooseWXPay({
								timestamp: res.data.list.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
								nonceStr: res.data.list.nonce_str, // 支付签名随机串，不长于 32 位
								package: 'prepay_id=' + res.data.list.prepay_id, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
								signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
								paySign: res.data.list.paySign, // 支付签名
								success: function(res) {
									//清除优惠券缓存
									_this.couponId = 0
									_this.couponName = '优惠券'
									_this.couponMoney = 0
									let coupon = {
										coupon_id: 0,
										name: '优惠券',
										coupon_money: 0
									}
									uni.setStorage({
										key: 'selectCoupon',
										data: coupon,
										success: () => {

										}
									})
									// 支付成功后的回调函数
									if (res.errMsg == 'requestPayment:ok') {
										let options = {
											msg: '归还成功',
											type: 'green'
										};
										_this.$refs.toast.showTips(options);
										//跳转支付成功页
										// setTimeout(function(){
										// uni.reLaunch({
										// 	url: '/pages/pay/success/success?amount='+_this.editRentFee
										// });	

										_this.$refer.setVilit('/pages/pay/success/success')
										let callback = function(url) {
											_this.$refs.popupvLogin.open()
										}
										var data = {
											amount: _this.editRentFee
										}
										_this.$refer.toUrl(callback, data, 'reLaunch')
										// },2000)

									}
								},
								fail: function(err) {
									// console.log(store.getters.orderNo)
									var opt = {
										url: '/coupon/clearCoupon',
										data: {
											order_no: store.getters.orderNo
											// order_no:"202010171849465f8acc4a24cca"
										},
										success: function(res) {

										},
									}

									_this.$service.GetApi(opt);
								}
							});

							// #endif 
							// #ifdef  MP-WEIXIN  || APP-PLUS
							// _this.payment = res.data.list.payment
							// _this.order_no = res.data.list.order_no

							// #ifdef  APP-PLUS

							const orderInfo = JSON.stringify({
								appid: res.data.list.appid,
								noncestr: res.data.list.nonce_str,
								package: 'Sign=WXPay',
								partnerid: res.data.list.partnerid,
								prepayid: res.data.list.prepay_id,
								timestamp: res.data.list.timeStamp,
								sign: res.data.list.sign.substring(0, 30),
							})
							// #endif
							uni.requestPayment({
								provider: 'wxpay',
								// #ifdef  MP-WEIXIN
								timeStamp: res.data.list.timeStamp,
								nonceStr: res.data.list.nonce_str,
								package: 'prepay_id=' + res.data.list.prepay_id,
								signType: 'MD5',
								paySign: res.data.list.paySign,
								// #endif
								// #ifdef  APP-PLUS
								orderInfo: orderInfo,
								// #endif
								success: function(res) {

									if (res.errMsg == 'requestPayment:ok') {
										let options = {
											msg: '归还成功',
											type: 'green'
										};
										_this.$refs.toast.showTips(options);
										//跳转支付成功页
										setTimeout(function() {
											// uni.reLaunch({
											// 	url: '/pages/pay/success/success?amount='+_this.editRentFee
											// });	
											_this.$refer.setVilit('/pages/pay/success/success')
											let callback = function(url) {
												_this.$refs.popupvLogin.open()
											}
											var data = {
												amount: _this.editRentFee
											}
											_this.$refer.toUrl(callback, data, 'reLaunch')
										}, 2000)

									}

								},
								fail: function(err) {
									var opt = {
										url: '/coupon/clearCoupon',
										data: {
											order_no: store.getters.orderNo
											// order_no:"202010171849465f8acc4a24cca"
										},
										success: function(res) {

										},
									}

									_this.$service.GetApi(opt);
								}
							});
							// #endif 

						} else if (res.status == 1 && res.code == 3000) {
							//月卡内支付
							let options = {
								msg: '归还成功',
								type: 'green'
							};
							_this.$refs.toast.showTips(options);
							//跳转支付成功页
							setTimeout(function() {
								// uni.reLaunch({
								// 	url: '/pages/pay/success/success?amount='+_this.editRentFee
								// });	
								_this.$refer.setVilit('/pages/pay/success/success')
								let callback = function(url) {
									_this.$refs.popupvLogin.open()
								}
								var data = {
									amount: _this.editRentFee
								}
								_this.$refer.toUrl(callback, data, 'reLaunch')
							}, 2000)
						} else {

							let options = {
								msg: res.message,
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);
							return;
						}


					}
				};

				_this.$service.GetApi(opt)

				//     }
				// });
			},
			checkShopOrderEstate() {
				let _this = this
				// console.log('payment_id轮询---', uni.getStorageSync('payment_id'))
				var opt = {
					url: '/order/checkShopOrderEstate',
					data: {
						payment_id: uni.getStorageSync('payment_id')
					},
					success: function(res) {
						if (res.status == 1) {
							_this.showMaskloading = false;
							clearInterval(_this.successTime); //关闭轮询
							_this.successTime = '';
							// console.log(res.message)
							uni.removeStorageSync('payment_id');
							let list = res.data.list;
							_this.$refer.setVilit('/pages/PayOrder/success');
							let data = {
								course:1
							}
							let callback = function(url) {
			
							}
							_this.$refer.toUrl(callback, data,'reLaunch')
						} else {
							console.log(res.message)
						}
			
					}
				};
			
				if (this.loginStatus) {
					this.$service.GetApi(opt) //网络
				}
			},
			
			useCoupon() {


				this.showCouponPopup = true;
				this.getCouponList();

			},
			// 关闭优惠卷弹窗
			closeCouponPopup() {
				this.showCouponPopup = false;
			},
			maskClose(data) {
				this.showCouponPopup = data;
			},
			getOverAndSale(data) {
				// 点击子组件传过来的值
				this.showCouponPopup = false;
				console.log(data)
				this.couponName = data.name;
				this.couponMoney = data.coupon_money;
				this.couponId = data.id;

			},
			// 获取优惠卷列表
			getCouponList() {
				let _this = this;
				console.log(_this.data.list)
				//_this.data.couponList.couponList = [];
				let couponObj = JSON.parse(JSON.stringify(_this.data.list)) //根据这里的价格过滤优惠券
				let oldPrice = parseFloat(couponObj.rent_fee); //商品原价

				// 可叠加状态 
				let opt = {
					url: '/coupon/canUseCoupon',
					data: {
						// related_type:1, //产品类型,配送租赁传1
						// related_id: couponObj.id, //产品id
						// store_id: '' //门店id
					},
					success: function(res) {
						//console.log(res)
						if (res.status == 1) {
							let result = [];
							let overReduce = []; //满减叠加
							let saleReduce = []; //折后可叠加
							let overAndSale = []; //满减和折后组合数组
							let finallyList = [];
							if (res.data.list.length) {
								// 1过滤掉达不到使用优惠卷和满减的数据
								result = res.data.list.filter(function(row) {
									return oldPrice >= row.spend_money

								})
							}

							result.forEach(function(cv) {
								if (cv.type == 1) {
									cv.coupon_money = (oldPrice - oldPrice * (parseFloat(cv.coupon_money))).toFixed(2); //折扣金额
								}
							})
							overReduce = result.filter((res) => {
								// 满减可叠加数组
								return res.type == 0 && res.is_overlay == 1
							})
							saleReduce = result.filter((res) => {
								// 折扣可叠加数组
								return res.type == 1 && res.is_overlay == 1
							});
							overReduce.forEach(function(res, i) {
								saleReduce.forEach(function(item) {
									// 后面可以在这里过滤组合,折扣后的价格达不到满减的
									let afterSalePrice = oldPrice * (parseFloat(item.coupon_money)); //折扣后的价格
									let overPrice = parseFloat(res.spend_money); //满减券
									let salePrice = parseFloat(item.spend_money); //折扣金额
									let sumCoupon = (salePrice + overPrice).toFixed(2); //总的优惠金额
									if (afterSalePrice >= overPrice) {
										overAndSale.push({
											overSaleList: [res, item],
											id: [item.id, res.id].join(','),
											tag_name: '组合券',
											name: item.name + '\n' + res.name,
											related_type_names: res.related_type_names,
											coupon_money: sumCoupon,
											use_start_at: res.use_start_at,
											use_expire_at: res.use_expire_at
										})
									}
								})
							});

							finallyList = JSON.parse(JSON.stringify(result))
							// 将可叠加的满减和折扣进行组合
							finallyList.push(...overAndSale);
							finallyList.sort(compare('coupon_money'));

							_this.data.couponList = JSON.parse(JSON.stringify(finallyList))
							console.log(_this.data.couponList)
						} else {
							let options = {
								msg: res.message,
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);
						}
					}
				}
				_this.$service.GetApi(opt)
			}




		}
	}
</script>

<style lang="scss">
	@import "./orderDetail.scss";

	page {}
</style>
